<template>
	<view class="list">
		<view class="bg">
			<view class="list-box">
				<view class="top">
					<view class="title">
						男生排行榜
					</view>
					<view class="more" @click="goRanking('male')">
						更多
					</view>
				</view>
				<view class="content">
					<view class="books-list" v-for="(item,index) in oneList" :key="index" @click="goDetail(item.sourceUrl)">
						<view class="books" v-if="index==0?true:false">
							<view class="left">
								<view class="num">
									{{index+1}}
								</view>
								<image :src="item.iconUrl" mode="widthFix"></image>
							</view>
							<view class="right">
								<view class="book-title">
									{{item.title}}
								</view>
								<view class="author">
									<view>
										{{item.author}}
									</view>
									<view class="label">
										{{item.category}}
									</view>
								</view>
								<view class="text">
									<text v-html="item.description"></text>
								</view>
							</view>
						</view>
						<view class="secondary" v-else>
							<view class="left">
								{{index+1}}
							</view>
							<view class="right">
								{{item.title}}
							</view>
						</view>
					</view>

				</view>

			</view>
			<view class="list-box">
				<view class="top">
					<view class="title">
						女生排行榜
					</view>
					<view class="more" @click="goRanking('female')">
						更多
					</view>
				</view>
				<view class="content">
					<view class="books-list" v-for="(item,index) in twoList" :key="index" @click="goDetail(item.sourceUrl)">
						<view class="books" v-if="index==0?true:false">
							<view class="left">
								<view class="num">
									{{index+1}}
								</view>
								<image :src="item.iconUrl" mode="widthFix"></image>
							</view>
							<view class="right">
								<view class="book-title">
									{{item.title}}
								</view>
								<view class="author">
									<view>
										{{item.author}}
									</view>
									<view class="label">
										{{item.category}}
									</view>
								</view>
								<view class="text">
									<text v-html="item.description"></text>
								</view>
							</view>
						</view>
						<view class="secondary" v-else>
							<view class="left">
								{{index+1}}
							</view>
							<view class="right">
								{{item.title}}
							</view>
						</view>
					</view>

				</view>
			</view>
			<view class="list-box" style="background-color: #FFE5B4;">
				<view class="top">
					<view class="title">
						图书排行榜
					</view>
					<view class="more" @click="goRanking('')">
						更多
					</view>
				</view>
				<view class="content">
					<view class="books-list" v-for="(item,index) in threeList" :key="index" @click="goDetail(item.sourceUrl)">
						<view class="books" v-if="index==0?true:false">
							<view class="left">
								<view class="num">
									{{index+1}}
								</view>
								<image :src="item.iconUrl" mode="widthFix"></image>
							</view>
							<view class="right">
								<view class="book-title">
									{{item.title}}
								</view>
								<view class="author">
									<view>
										{{item.author}}
									</view>
									<view class="label">
										{{item.category}}
									</view>
								</view>
								<view class="text">
									<text v-html="item.description"></text>
								</view>
							</view>
						</view>
						<view class="secondary" v-else>
							<view class="left">
								{{index+1}}
							</view>
							<view class="right">
								{{item.title}}
							</view>
						</view>
					</view>

				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'list',
		data() {
			return {
				oneList: [],
				twoList: [],
				threeList: [],
			};
		},
		onLoad() {
			uni.showLoading({
				title: '正在加载中'
			})
			this.getOne();
			this.getTwo();
			this.getThree();
		},
		methods: {
			getOne() {
				uni.request({
					url: 'https://apis.netstart.cn/yunyuedu/rank/original/list/data.json?gender=male&sortType=day&type=sell',
					method: 'GET',
				}).then(res => {
					// console.log('res ==> ', res);
					for (let i = 0; i < 5; i++) {
						this.oneList.push(res.data.data.books[i])
					}
					console.log('this.oneList ==> ', this.oneList);
					uni.hideLoading()
				}).catch(err => {
					console.log('err ==> ', err);
				})
			},
			getTwo() {
				uni.request({
					url: 'https://apis.netstart.cn/yunyuedu/rank/original/list/data.json?gender=female&sortType=day&type=sell',
					method: 'GET',
				}).then(res => {
					// console.log('res ==> ', res);
					for (let i = 0; i < 5; i++) {
						this.twoList.push(res.data.data.books[i])
					}
					// console.log('this.twoList ==> ', this.twoList);
					uni.hideLoading()
				}).catch(err => {
					console.log('err ==> ', err);
				})
			},
			getThree() {
				uni.request({
					url: 'https://apis.netstart.cn/yunyuedu/rank/publish/list/data.json?sortType=day&type=sell',
					method: 'GET',
				}).then(res => {
					// console.log('res ==> ', res);
					for (let i = 0; i < 5; i++) {
						this.threeList.push(res.data.data.books[i])
					}
					// console.log('this.threeList ==> ', this.threeList);
					uni.hideLoading()
				}).catch(err => {
					console.log('err ==> ', err);
				})
			},
			goRanking(gender){
				// console.log(gender);
				uni.navigateTo({
					url:'../ranking/ranking?gender='+gender
				})
			},
			goDetail(id){
				id = id.replace('/source/','')
				let user = uni.getStorageSync('userInfo');
				if (!user) {
					uni.showToast({
						title: '未登录,请先去登录',
						icon: 'none'
					})
				} else {
					uni.navigateTo({
						url: '../detail/detail?id=' + id
					})
				}
			},

		}
	}
</script>

<style lang="scss">
	.bg {
		width: 100%;
		// height: 100vh;
		background-image: url('../../static/background-image.png');
		background-repeat: no-repeat;
	}

	.list-box {
		width: 100%;
		height: 716rpx;

		.top {
			height: 140rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.title {
				font-weight: 700;
				margin-left: 30rpx;
				font-size: 40rpx;
				
			}

			.more {
				width: 80rpx;
				height: 46rpx;
				border-radius: 26rpx;
				background-color: #FCE2B2;
				margin-right: 40rpx;
				font-size: 24rpx;
				text-align: center;
				line-height: 46rpx;
				color: #999999;
				border: 1px solid #FC768A;
			}
		}

		.content {
			height: 570rpx;
			background-color: #FBEBCB;

			.books {
				display: flex;
				height: 240rpx;
				// margin-top: 40rpx;
				padding-top: 30rpx;
				margin-bottom: 40rpx;

				.left {
					position: relative;
					width: 180rpx;
					height: 240rpx;
					border-radius: 24rpx;
					margin-left: 30rpx;

					image {
						width: 100%;
						display: block;
						border-radius: 20rpx;
					}

					.num {
						width: 36rpx;
						height: 35rpx;
						z-index: 1;
						position: absolute;
						left: 20rpx;
						text-align: center;
						color: white;
						font-size: 24rpx;
						line-height: 35rpx;
						background-image: url('https://easyreadfs.nosdn.127.net/web/trunk/1476860251636/top1.png');
						background-repeat: no-repeat;
						background-position: center;
						background-size: cover;

					}
				}

				.right {
					margin-left: 30rpx;

					.book-title {
						font-size: 36rpx;
						font-weight: 700;
						margin-top: 18rpx;
						width: 400rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						
					}

					.author {
						display: flex;
						align-items: center;
						color: #999999;
						font-size: 28rpx;
						margin-top: 18rpx;
						// width: 200rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
						.label {
							margin-left: 20rpx;
							padding: 0 10rpx;
							height: 36rpx;
							border: 1px solid #FC768A;
							border-radius: 10rpx;
							font-size: 24rpx;
							color: #999999;
							text-align: center;
							line-height: 36rpx;
							background-color: #FCE2B2;
						}
					}

					.text {
						margin-top: 18rpx;
						width: 424rpx;
						height: 84rpx;
						font-size: 30rpx;
						color: #77828A;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}
				}
			}

			.secondary {
				width: 690rpx;
				height: 40rpx;
				margin-top: 20rpx;
				margin-left: 50rpx;
				display: flex;
				align-items: center;

				.left {
					width: 36rpx;
					height: 35rpx;
					text-align: center;
					color: white;
					font-size: 24rpx;
					line-height: 35rpx;
					background-image: url('https://easyreadfs.nosdn.127.net/web/trunk/1476860251636/top1.png');
					background-repeat: no-repeat;
					background-position: center;
					background-size: cover;

				}

				.right {
					font-size: 28rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
</style>